<table id="dg" title="图片列表" style="width:550px;height:250px">
</table>

<div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="updateuser()">编辑图片</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除图片</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="adduser()">增加图片</a>


    <label>目录：</label>
    <select name='cid' id='cid' class="form-control" style='width:120px;margin: 0'>
        <option value=""></option>
    {{range $index, $e :=.category}}
        <option value={{$e.Id}}>{{$e.Title}}</option>
    {{range $index1, $e1 :=$e.Son}}
        <option value={{$e1.Id}}>-------{{$e1.Title}}</option>
    {{end}}
    {{end}}
    </select>
    <label>状态：</label>
    <select id='status' class="form-control" name='status' style='width:120px;margin: 0 5px'>
        <option value=-1></option>
        <option value=1>已开启</option>
        <option value=0>已关闭</option>
    </select>
    <label>置顶：</label>
        <select id='top' class="form-control" name='top' style='width:120px;margin: 0 5px'>
        <option value=-1></option>
        <option value=1>已置顶</option>
        <option value=0>未置顶</option>
    </select>
    <label>轮转：</label>
        <select id='roll' class="form-control" name='roll' style='width:120px;margin: 0 5px'>
        <option value=-1></option>
        <option value=1>已轮转</option>
        <option value=0>未轮转</option>
    </select>
    <a href="#" class="easyui-linkbutton" onclick="getabout()">查询</a>

</div>

<script type="text/javascript">
    $('#dg').datagrid({
        url: '/picture/photo/index',
        collapsible: true,
        toolbar: '#toolbar',
        rownumbers: true,
        pagination: true,
        pageList: [5, 10, 30],
        fit: true,
        columns: [[
            {field: 'ck', checkbox: true},
            {field: 'Id', title: '单页ID', width: 100, hidden: true},
            {
                field: 'Title', title: '标题', width: 120,
                formatter: function (value, row, index) {
                    return "<a target='_blank' href='/" + row.Cid + "/" + row.Id + "'>" + value + "</a>";
                }
            }, {
                field: 'Photo',
                title: '封面',
                width: 100,
                formatter: function (value, row, index) {
                    return "<a href='" + value + "' target='_blank'>" + "Picture" + "</a>";
                }
            },
            {field: 'Author', title: '作者', width: 120},
            {field: 'Cid', title: '目录', width: 120},
            {
                field: 'Createtime', title: '创建时间', width: 120,
                formatter: function (value, row, index) {
                    if (value) return phpjs.date("Y-m-d H:i:s", phpjs.strtotime(value));
                    return value;
                }
            },
            {
                field: 'Updatetime', title: '更新时间', width: 120,
                formatter: function (value, row, index) {
                    if (value) return phpjs.date("Y-m-d H:i:s", phpjs.strtotime(value));
                    return value;
                }
            },
            {field: 'View', title: '浏览量', width: 100},
            {field: 'Sort', title: '排序', width: 100},
            {
                field: 'Status', title: '状态', width: 120,
                formatter: function (value, row, index) {
                    //alert(value);
                    $para = row.Id + ',';
                    if (value == 1) {
                        return "已开启|<button style='color:red;font-size:1.1em;margin-left:10px;cursor:pointer' onclick='updatestatus(" + $para + "0)'>关闭</a>";
                    } else {
                        return "已关闭|<button style='color:red;font-size:1.1em;margin-left:10px;cursor:pointer' onclick='updatestatus(" + $para + "1)'>开启</a>";
                    }
                }
            }
            ,
            {
                field: 'Istop', title: '是否置顶', width: 120,
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "置顶";
                    } else {
                        return "不置顶";
                    }
                }
            }
            ,
            {
                field: 'Isroll', title: '是否轮转', width: 120,
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "已轮转";
                    } else {
                        return "无";
                    }
                }
            }
            ,
            {
                field: 'Rollpath', title: '自定义轮转地址', width: 120,
                formatter: function (value, row, index) {
                    return  "<a href='"+value+"' target='_blank'>"+value+"</a>"
                }
            }

        ]]
    });


    function destroyUser() {
        var rows = $('#dg').datagrid('getSelections');
        if (rows.length != 0) {
            $.messager.confirm('Confirm', '你确定要删除，删除后在回收站?', function (r) {
                if (r) {
                    var uri = "/picture/photo/deletepaper";
                    for (var i = 0; i < rows.length; i++) {
                        var row = rows[i];
                        $.post(uri, {'id': row.Id}, function (result) {
                            $.messager.show({	// show error message
                                title: '消息',
                                msg: result.info
                            });
                            $('#dg').datagrid('reload');	// reload the user da
                        });
                    }
                }
            });
        } else {
            alert("请勾选按钮")
        }
    }


    function updateuser() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            window.open("/picture/photo/updatepaper?id=" + row.Id);
        } else {
            alert("请勾选按钮")
        }
    }

    function adduser() {
        window.open("/picture/photo/addpaper");
    }


    function getabout() {
        var status = $('#status').val();
        var cid = $('#cid').val();
        var top=$("#top").val();
        var roll=$("#roll").val();
        $('#dg').datagrid('load', {
            status: status,
            cid: cid,
            top:top,
            roll:roll
        });
    }

    function updatestatus(id, status) {
        $.post('/picture/photo/updatepaper', {'small':1,'id': id, 'status': status}, function (result) {
            $.messager.show({	// show error message
                title: '消息',
                msg: result.info
            });
            $('#dg').datagrid('reload');	// reload the user da
        });

    }
</script>